const app = getApp()
Component({
  properties: {
    // selectType: {
    //   type: [String]
    // },
  },
  data: {
    // selected: 0,
    color: "#000000",
    selectedColor: "#EC261E",
    uselist:[],
    list: [ {
      "pagePath": "/pages/index/index",
      "text": "首页",
      "iconPath": "/images/index.png",
      "selectedIconPath": "/images/indexSelect.png"
    },
    {
      "pagePath": "/pages/my/my",
      "text": "我的",
      "iconPath": "/images/my.png",
      "selectedIconPath": "/images/mySelect.png"
    }],
    list2: [{
      "pagePath": "/pages/localindex/localindex",
      "text": "首页",
      "iconPath": "/images/index.png",
      "selectedIconPath": "/images/indexSelect.png"
    },
    {
      "pagePath": "/pages/pastpage/pastpage",
      "text": "往期",
      "iconPath": "/images/past.png",
      "selectedIconPath": "/images/pastSelect.png"
    },
    {
      "pagePath": "/pages/my/my",
      "text": "我的",
      "iconPath": "/images/my.png",
      "selectedIconPath": "/images/mySelect.png"
    }]
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      let index = ''
      getCurrentPages().length>=1 ? index = getCurrentPages().length - 1 : index = 0
      const url = `/${getCurrentPages()[index].route}`
      switch(url){
        case '/pages/index/index' :
          this.setData({selected: 0})
          break;
          case '/pages/localindex/localindex' :

            this.setData({selected: 0})
            break;
        case '/pages/my/my' :
          app.globalData.tabBarType == "index" ? this.setData({selected: 1}) : this.setData({selected: 2})
          break;
        case '/pages/pastpage/pastpage' :
          this.setData({selected: 1})
          break;
        case '/pages/localindex/localindex' :
          this.setData({selected: 1})
          break;
      }
    }
  },
  lifetimes: {   
    attached: function() {
      console.log(app.globalData.tabBarType)
      // 在组件实例进入页面节点树时执行
      if(app.globalData.tabBarType == 'index'){
        this.setData({uselist: this.data.list})
      }else if(app.globalData.tabBarType == 'local'){
        this.setData({uselist: this.data.list2})
      }
    },
    moved(){
      console.log('moved-moved')
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  methods: {
    switchTab(e) {
      let index = ''
      getCurrentPages().length>=1 ? index = getCurrentPages().length - 1 : index = 0
      const data = e.currentTarget.dataset
      const url = data.path
      const currentRoute = `/${getCurrentPages()[index].route}`
      console.log(getCurrentPages())
      console.log(url,this.data.selected)
      // console.log(data, `/${getCurrentPages()[0].route}`, data.path)
      if(url == currentRoute) return false
      wx.reLaunch({url})
     
    }
  }
})